#pragma once
#include <qbnet/include/network_service.h>

#include <QMenu>
#include <QMetaType>
#include <QPushButton>
#include <QWidget>

class SImageButton;
class QLabel;
class QPushButton;
class QPainterPath;

class SButtonTips : public QWidget {
  Q_OBJECT
 public:
  enum AlginArrow {
    AlignLeft = 0,  // 箭头在左边
    AlignTop,       // 箭头在上边
    AlignRight,     // 箭头在右边
    AlignBottom     // 箭头在下边
  };
  explicit SButtonTips(QWidget* parent = nullptr);
  ~SButtonTips();

  void setAlign(AlginArrow align) { m_alginArrow = align; }
  void setStartX(int pos) { m_startPos = pos; }
  void setIconVisible(bool visible) {}
  void setIcon(const QString& icon) {}
  void setLabelText(const QString& txt);
  void setButtonText(const QString& txt);
  void setButtonVisible(bool visible);
  void setButtonColor(QColor bkgColor, QColor txtColor);
  void setBkgColor(QColor color) { m_bkgColor = color; }
  void setBorderColor(QColor color) { m_borderColor = color; }

 signals:
  void onButtonClicked();

 protected:
  void paintEvent(QPaintEvent* event) override;

 protected slots:
  void onTryAgainClicked();

 private:
  QPainterPath* makeDrawPath();

 private:
  int m_startPos;
  SImageButton* m_icon;
  QString m_labelTxt;
  QLabel* m_label;
  QString m_btnTxt;
  QPushButton* m_button;
  QColor m_btnTxtColor;
  QColor m_btnBkgColor;
  AlginArrow m_alginArrow;
  QColor m_bkgColor;
  QColor m_borderColor;
};

class MainFrame;
class SImageButton;
class StatusBar : public QWidget {
  Q_OBJECT
 public:
  StatusBar(MainFrame* frame, QWidget* parent = nullptr);
  ~StatusBar();

  void addBtn(QWidget* btn, QWidget* before);
 signals:
  void networkStateChanged(int state);

 private:
  void initialize();
  QString getSystemTime();

 private:
  MainFrame* m_frame = nullptr;
  QTimer* m_tmSysTime = nullptr;
};
